<script>
//app.js
var util = require("./utils/util.js");
// import "./umtrack-wx";

export default {
  globalData: {
    umengConfig: {
      appKey: '5fd0c2b1bed37e4506c7ba9b',
      //由友盟分配的APP_KEY
      useOpenid: true,
      // 是否使用openid进行统计，此项为false时将使用友盟+随机ID进行用户统计。使用openid来统计微信小程序的用户，会使统计的指标更为准确，对系统准确性要求高的应用推荐使用OpenID。
      autoGetOpenid: true,
      // 是否需要通过友盟后台获取openid，如若需要，请到友盟后台设置appId及secret
      debug: false,
      //是否打开调试模式
      uploadUserInfo: false // 自动上传用户信息，设为false取消上传，默认为false

    },

    // 监听页面不存在
    onPageNotFound(res) {
      uni.redirectTo({
        url: 'pages/index/index'
      });
    },

    platform: "wx",
    pathDetail: "",
    extConfig: null,
    openid: "",
    version: "21.08.26",
    showTap: true,
    tAppid: "wx8abaf00ee8c3202e",
    textraData: {
      id: '152540',
      customData: {
        clientInfo: "",
        clientVersion: ""
      }
    },
    shareImage: "",
    shareTitle: "",
    api: 'https://api1.bendibao.com/banshitong/index.php',
    apibak: 'https://api.bendibao.com/banshitong/index.php',
    url: {
      urltest1: "https://wxapidg.bendibao.com/apitest.php",
      urltest2: "https://wxapisz.bendibao.com/apitest.php",
      host1: "https://wxapidg.bendibao.com",
      host2: "https://wxapisz.bendibao.com"
    } // url: {
    //     urltest1: "https://wxapidg.bendibao.com/apitest.php",
    //     urltest2: "https://wxapisz.bendibao.com/apitest.php",
    //     host1: "https://szapi.bendibao.com",
    //     host2: "https://szapi.bendibao.com",
    // },

  },
  onLaunch: function (opt) {
    var randomNum1 = Math.ceil(Math.random() * 10); // 主要获取1到10的随机整数，取0的几率极小。

    if (randomNum1 % 2 == 0) {
      [this.globalData.url.urltest2, this.globalData.url.host2, this.globalData.url.urltest1, this.globalData.url.host1] = [this.globalData.url.urltest1, this.globalData.url.host1, this.globalData.url.urltest2, this.globalData.url.host2];
    }

    this.globalData.pathDetail = opt; // 获取用户的手机型号

    uni.getSystemInfo({
      success: res => {
        this.globalData.textraData.customData.clientInfo = res.system;
        this.globalData.textraData.customData.clientVersion = res.version;
      }
    }); // 获取本程序的appid
    // let accountInfo = wx.getAccountInfoSync().miniProgram;

    var city = uni.getStorageSync('city');
    util.getUrl(this.globalData.url).then(res => {
      // 登录
      uni.login({
        success: res => {
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
          let loginData = {
            action: "login",
            // appid: accountInfo.appId,
            appid: "wx2efc0705600eb6db",
            code: res.code
          };
          util.request('user.php', loginData, 'POST').then(res => {
            if (res.data.data) {
              uni.setStorageSync("openid", res.data.data.openid);
              uni.setStorageSync("session_key", res.data.data.session_key);
              uni.setStorageSync("unionid", res.data.data.unionid);
            }
          });
        }
      });
    });
  },

  // 监听页面错误
  onError(err) {
    // 报错页面分析
    uni.reportAnalytics('check_article', {
      id: Number(this.globalData.pathDetail.query.id),
      type: this.globalData.pathDetail.query.type,
      city: this.globalData.pathDetail.query.city,
      scene: this.globalData.pathDetail.scene,
      path: this.globalData.pathDetail.path,
      err_reason: err
    });
  },

  methods: {}
};
</script>
<style>
/**app.wxss**/

.container {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 200rpx 0;
    box-sizing: border-box;
}


/* 弹框 */

.tkbox {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    position: fixed;
    top: 0;/*  #ifdef  H5  */
    top: calc(88rpx + constant(safe-area-inset-top));
    top: calc(88rpx + env(safe-area-inset-top));/*  #endif  */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cont-box {
    width: 558rpx;
    height: 686rpx;
    background: rgba(255, 255, 255, 1);
    opacity: 1;
    border-radius: 40rpx;
    position: relative;
}

.icon {
    width: 29rpx;
    height: 29rpx;
    position: absolute;
    right: 43rpx;
    top: 37rpx;
}

.cont {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 80rpx 50rpx 0 50rpx;
}

.cont text {
    font-size: 28rpx;
    font-family: PingFang SC;
    font-weight: 600;
    color: rgba(20, 20, 20, 1);
    opacity: 1;
    line-height: 45rpx;
}

.cont image {
    width: 450rpx;
    height: 314rpx;
    margin-top: 30rpx;
}

.cont button {
    width: 100%;
    background: rgba(255, 102, 0, 1);
    padding: 8rpx 0;
    opacity: 1;
    border-radius: 40rpx;
    font-size: 26rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: rgba(255, 255, 255, 1);
    text-align: center;
    line-height: 64rpx;
    margin-top: 40rpx;
}

button::after {
    border: 0;
}


/* 底部 */

.app-bottom {
    width: 100%;
    opacity: 1;
    padding: 20rpx 0;
    text-align: center;
}

.app-bottom image {
    width: 154rpx;
    height: 62rpx;
}

.app-bottom text {
    font-size: 28rpx;
    font-family: PingFang SC, PingFang SC-Medium;
    font-weight: 500;
    text-align: center;
    color: #989696;
}

.navigator-hover {
    background-color: transparent;
}

.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.row {
    display: flex;
    align-items: center;
}

.flex {
    display: flex;
    align-items: center;
}

.center {
    align-items: center;
    justify-content: center;
}

.col {
    flex-direction: column;
}

.around {
    justify-content: space-around;
}

.row-flex-end {
    justify-content: flex-end;
}

.flex-start {
    justify-content: flex-start;
}
.fgx {
    height: 16rpx;
    background: #f7f7f7;
}
.text-over {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	word-break: break-all;
}
</style>